home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / arp.h < prev    next >
C/C++ Source or Header  |  1991-04-13  |  5KB  |  130 lines

  1. /* @(#) $Header: arp.h,v 1.6 91/04/12 18:34:32 deyke Exp $ */
  2.  
  3. #ifndef _ARP_H
  4. #define _ARP_H
  5.  
  6. #ifndef _GLOBAL_H
  7. #include "global.h"
  8. #endif
  9.  
  10. #ifndef _MBUF_H
  11. #include "mbuf.h"
  12. #endif
  13.  
  14. #ifndef _IFACE_H
  15. #include "iface.h"
  16. #endif
  17.  
  18. #ifndef _TIMER_H
  19. #include "timer.h"
  20. #endif
  21.  
  22. /* Lifetime of a valid ARP entry */
  23. #define ARPLIFE         (0x7fffffff / 1000)
  24. /* Lifetime of a pending ARP entry */
  25. #define PENDTIME        15      /* 15 seconds */
  26.  
  27. /* ARP definitions (see RFC 826) */
  28.  
  29. #define ARPLEN  16              /* Size of ARP hdr, minus hardware addresses */
  30.  
  31. /* Address size definitions */
  32. #define IPALEN  4               /* Length in bytes of an IP address */
  33. #define MAXHWALEN       255     /* Maximum length of a hardware address */
  34.  
  35. /* ARP opcodes */
  36. #define ARP_REQUEST     1
  37. #define ARP_REPLY       2
  38. #define REVARP_REQUEST  3
  39. #define REVARP_REPLY    4
  40.  
  41. /* Hardware types */
  42. #define ARP_NETROM      0       /* Fake for NET/ROM (never actually sent) */
  43. #define ARP_ETHER       1       /* Assigned to 10 megabit Ethernet */
  44. #define ARP_EETHER      2       /* Assigned to experimental Ethernet */
  45. #define ARP_AX25        3       /* Assigned to AX.25 Level 2 */
  46. #define ARP_PRONET      4       /* Assigned to PROnet token ring */
  47. #define ARP_CHAOS       5       /* Assigned to Chaosnet */
  48. #define ARP_IEEE802     6       /* Who uses this? */
  49. #define ARP_ARCNET      7
  50. #define ARP_APPLETALK   8
  51. extern char *Arptypes[];        /* Type fields in ASCII, defined in arpcmd */
  52. #define NHWTYPES 9
  53.  
  54. /* Table of hardware types known to ARP */
  55. struct arp_type {
  56.     int16 hwalen;           /* Hardware length */
  57.     int16 iptype;           /* Hardware type field for IP */
  58.     int16 arptype;          /* Hardware type field for ARP */
  59.     int16 pendtime;         /* # secs to wait pending response */
  60.     char *bdcst;            /* Hardware broadcast address */
  61.     char *(*format) __ARGS((char *,char *));
  62.                 /* Function that formats addresses */
  63.     int (*scan) __ARGS((char *,char *));
  64.                 /* Reverse of format */
  65. };
  66. extern struct arp_type Arp_type[];
  67. #define NULLATYPE       (struct arp_type *)0
  68.  
  69. /* Format of an ARP request or reply packet. From p. 3 */
  70. struct arp {
  71.     int16 hardware;                 /* Hardware type */
  72.     int16 protocol;                 /* Protocol type */
  73.     char hwalen;                    /* Hardware address length, bytes */
  74.     char pralen;                    /* Length of protocol address */
  75.     int16 opcode;                   /* ARP opcode (request/reply) */
  76.     char shwaddr[MAXHWALEN];        /* Sender hardware address field */
  77.     int32 sprotaddr;                /* Sender Protocol address field */
  78.     char thwaddr[MAXHWALEN];        /* Target hardware address field */
  79.     int32 tprotaddr;                /* Target protocol address field */
  80. };
  81.  
  82. /* Format of ARP table */
  83. struct arp_tab {
  84.     struct arp_tab *next;   /* Doubly-linked list pointers */
  85.     struct arp_tab *prev;
  86.     struct timer timer;     /* Time until aging this entry */
  87.     struct mbuf *pending;   /* Queue of datagrams awaiting resolution */
  88.     int32 ip_addr;          /* IP Address, host order */
  89.     int16 hardware;         /* Hardware type */
  90.     char state;             /* (In)complete */
  91. #define ARP_PENDING     0
  92. #define ARP_VALID       1
  93.     char pub;               /* Respond to requests for this entry? */
  94.     char *hw_addr;          /* Hardware address */
  95. };
  96. #define NULLARP (struct arp_tab *)0
  97. extern struct arp_tab *Arp_tab[];
  98.  
  99. struct arp_stat {
  100.     unsigned recv;          /* Total number of ARP packets received */
  101.     unsigned badtype;       /* Incoming requests for unsupported hardware */
  102.     unsigned badlen;        /* Incoming length field(s) didn't match types */
  103.     unsigned badaddr;       /* Bogus incoming addresses */
  104.     unsigned inreq;         /* Incoming requests for us */
  105.     unsigned replies;       /* Replies sent */
  106.     unsigned outreq;        /* Outoging requests sent */
  107. };
  108. extern struct arp_stat Arp_stat;
  109.  
  110. /* In arp.c: */
  111. struct arp_tab *arp_add __ARGS((int32 ipaddr,int hardware,char *hw_addr,
  112.     int pub));
  113. void arp_drop __ARGS((void *p));
  114. int arp_init __ARGS((unsigned int hwtype,int hwalen,int iptype,int arptype,
  115.     int pendtime,char *bdcst,char *(*format) __ARGS((char *,char *)),
  116.     int  (*scan) __ARGS((char *,char *)) ));
  117. void arp_input __ARGS((struct iface *iface,struct mbuf *bp));
  118. struct arp_tab *arp_lookup __ARGS((int hardware,int32 ipaddr));
  119. char *res_arp __ARGS((struct iface *iface,int hardware,int32 target,struct mbuf *bp));
  120.  
  121. /* In arphdr.c: */
  122. struct mbuf *htonarp __ARGS((struct arp *arp));
  123. int ntoharp __ARGS((struct arp *arp,struct mbuf **bpp));
  124.  
  125. /* In arpfile.c: */
  126. void arp_savefile __ARGS((void));
  127. void arp_loadfile __ARGS((void));
  128.  
  129. #endif /* _ARP_H */
  130.